package com.lx.wrapper.every;


import cn.hutool.core.collection.CollectionUtil;
import com.lx.constant.enums.PreConditionTypeEnum;
import com.lx.constant.enums.SegmentEnum;
import com.lx.constant.segment.Segment;
import com.lx.wrapper.AbstractEveryEntityLambdaConditionWrapper;
import com.lx.wrapper.AbstractWrapper;
import org.hibernate.query.Query;

import java.util.List;
import java.util.Map;

/**
 * Lambda SQL On条件语法操作对象
 * 注意：
 * 1. 此Wrapper下不支持LIMIT操作。
 *
 * @author lx
 * @create 2023/2/25 16:06
 **/
public class LambdaOnConditionWrapper extends AbstractEveryEntityLambdaConditionWrapper<Object, LambdaOnConditionWrapper> {

    /**
     * 获取On条件类型的Wrapper
     *
     * @return
     */
    public static LambdaOnConditionWrapper getOnConditionWrapper() {
        return new LambdaOnConditionWrapper();
    }

    public LambdaOnConditionWrapper() {
        super(null);
        setPreConditionType(PreConditionTypeEnum.ON);
    }

    @Override
    public LambdaOnConditionWrapper where() {
        log.warn("回正前置条件=[Where]失败,此处不允许设置非[ON]系列的其他条件");
        return this;
    }

    @Override
    protected void setHibernateParamByQuery0(boolean isHQL, Query query) {
        //其他映射
        Map<SegmentEnum, List<Segment>> segmentsMap = getSegmentsByEnums(SegmentEnum.ON);
        segmentsMap.forEach((e1, l1) -> {
            if (CollectionUtil.isEmpty(l1)) {
                return;
            }
            for (Segment sn : l1) {
                sn.setHibernateParamByQuery(isHQL, query);
            }
        });
    }

    @Override
    protected String getCompleteQL0(boolean isHQL, AbstractWrapper parentWrapper) {
        //仅获取ON关键字组成
        return buildConditions(isHQL, parentWrapper, SegmentEnum.ON);
    }
}
